var globals = globals || {};
globals.$ = jQuery;
if(typeof globals.UserStatusCallback != "function" )
    globals.UserStatusCallback = function(){};
globals.SubString = function (str, len) {
    if (!str || !len) return '';
    var a = 0;
    var i = 0;
    var temp = '';

    for (i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) > 255)
            a += 2;
        else
            a++;
        if (a > len) return temp + "...";
        temp += str.charAt(i);
    }
    return str;
};
globals.UserStatus = function(){
    if(!globals.disableUserStatus){
        var reffer = window.location.href;
        globals.$.getJSON("http://service.5sing.com/api/user.php?method=checkStatus&jsoncallback=?", { url: reffer }, function (obj) {
            if (obj.isLogin) {
                var html = '<ul class="top_nav_join"><li><a class="myspace" href="http://www.5sing.com/my/">个人中心</a></li>';
                html += '<li class="top_nav_user h_nav_box"><a href="http://www.5sing.com/'
                    + obj.id +'" class="h_nav_clo">' + globals.SubString(obj.nickname,10) + '</a></li>';
                html += '<li class="top_nav_user quit"><a href="http://www.5sing.com/logout">[退出]</a></ li>';
                html += '<li class="ctop cnav_note"><a href="http://www.5sing.com/my/message/note" title="消息">' + (obj.totalmessage > 0 ? '<b class="top_nav_new"></b>' : '') + '<span>消息</span></a></li>';
                html += '<li class="ctop cnav_dress"><a href="http://www.5sing.com/my/set/photo" title="设置"><span>设置</span></a></li></ul>';
                globals.$(".top_nav").html(html);
                globals.UserStatusCallback(obj);
            }
            else
                globals.UserStatusCallback(false);
        });
    }
};
globals.AddFriends = function(userIds, callback){
    if(typeof callback != "function"){
        callback = function (o) {
            if(!o.isLogin)
                globals.$.login();
            else
            {
                if(o.isSuccess)
                    globals.$.tips("关注成功");
                else
                    globals.$.tips(o.message);
            }
        };
    }
    $.getJSON("http://service.5sing.com/relation/addFriends?jsoncallback=?", { userIds: userIds }, callback);
};
globals.RemoveFriends = function(userIds, callback){
    if(typeof callback != "function"){
        callback = function (o) {
            if(o.isSuccess)
                globals.$.tips("取消关注成功");
            else
                globals.$.tips(o.message);
        };
    }
    globals.$.getJSON("http://service.5sing.com/relation/removeFriends?jsoncallback=?", { userIds: userIds }, callback);
};
globals.collectSong = function(songId, songType, callback){
    if(typeof callback != "function"){
        callback = function (isSuccess) {
        };
    }
    globals.$.getJSON("http://service.5sing.com/song/collect?jsoncallback=?", { songId: songId, songType: songType }, function(res){
        var isSuccess = res.code == 0 ||  res.code == 4;
        $.tips(res.msg);
        callback(isSuccess);
    });
};
globals.deleteCollectSong = function(songId, songType, callback){
    if(typeof callback != "function"){
        callback = function (isSuccess) {
        };
    }
    globals.$.getJSON("http://service.5sing.com/song/deleteCollect?jsoncallback=?", { songId: songId, songType: songType }, function(res){
        var isSuccess = res.code == 0;
        $.tips(res.msg);
        callback(isSuccess);
    });
};
globals.getAvatar = function(src, width, height, model){
    if(!src || !width)
        return src;
    if(!height)
        height = width;
    if(!!model){
        if(model == "force")
            src = src.replace("/m/", "/force/");
        else if(model == "m")
            src = src.replace("/force/", "/m/");
    }
    if(src.match(/_\d+_\d+\.(jpg|png|gif|bmp)/i))
        return src.replace(/_\d+_\d+\.(jpg|png|gif|bmp)/i, "_" + width + "_" + height + ".$1");
    else
        return src.replace(/\.(jpg|png|gif|bmp)/i,  "_" + width + "_" + height + ".$1");
};
(function($){
    $.tips = function(msg, delay, reload){
        var style = '<style>.show_public_tips{ position:fixed; _position:absolute; top:30%; left:50%; width:360px; margin:0 0 0 -200px;'
            + ' background:#000; font-size:18px; font-family:\'Microsoft Yahei\',微软雅黑; text-align:center; line-height:40px; '
            + 'padding:20px; z-index:21000; _top:expression(documentElement.scrollTop + 150); border:1px solid #555; color:#fff;} '
            + '.show_public_tips_text{ color:#fff;}</style><!--[if (gt IE 9)|!(IE)]><!--><style> div.show_public_tips{ background:rgba(0, 0, 0, 0.7);'
            + 'border-radius:8px;}</style><!--<![endif]-->';
//        var style = '<style>.show_public_tips{ position:fixed; _position:absolute; top:30%; left:50%; width:400px; margin:0 0 0 -200px;'
//            +' background:#000; background:rgba(0, 0, 0, 0.7); font-size:18px; font-family:\'Microsoft Yahei\',微软雅黑;'
//            +' text-align:center; line-height:80px; height:80px; z-index:21000;filter:Alpha(opacity=70); border-radius:8px;'
//            +' _top:expression(documentElement.scrollTop + 150); display:none; border:1px solid #555;} .show_public_tips_text{ color:#fff;}</style>';
        var html = '<div class="show_public_tips"><p class="show_public_tips_text"></p></div>';
        var tipsObj = globals.$(".show_public_tips");
        if(tipsObj.length <= 0)
        {
            globals.$("body").append(style + html);
            tipsObj = globals.$(".show_public_tips");
        }
        tipsObj.stop().hide();
        if(Object.prototype.toString.call((delay)) != '[object Array]' || delay.length != 3)
            delay = [500, 1000, 500];
        tipsObj.css("opacity", 0).show().find(".show_public_tips_text").html(msg).parent().animate({"opacity": 1}, delay[0], function(){
            tipsObj.animate({"opacity": 1}, delay[1], function(){
                tipsObj.animate({"opacity": 0}, delay[2], function(){
                    tipsObj.hide();
                    if(reload === true){
                        window.location.reload();
                    }
                    else if(!!reload){
                        window.location.href = reload;
                    }
                });
            });
        });
    };
    $.login = function(callback){
        var self = this;
        var style = '<style>html{_background-image:url(about:blank);_background-attachment:fixed;}'
            +'.pop_lo_bg_bg{background:rgba(0, 0, 0, .5); background:#000\\9;opacity:0.5\\0;position:fixed; width:100%; height:100%; top:0; left:0; display:block; filter:Alpha(opacity=50); z-index:11000;_position:absolute; _height:expression(document.body.clientHeight+\'px\');}'
            +'.pop_lo_bg{position:absolute; left:20%; z-index:11001; top:20%; background:#fff; overflow:hidden; -webkit-box-shadow:0 0 5px rgba(0,0,0,0.3); -moz-box-shadow:0 0 5px rgba(0,0,0,0.3); box-shadow:0 0 5px rgba(0,0,0,0.3); width:540px;}'
            +'.pop_lo_bg .rt{ float:right;}'
            +'.pop_lo_bg .lt{float:left}'
            +'ul.pop_lo_list{position:relative; overflow:hidden; padding:20px 0 0 0;}'
            +'ul.pop_lo_list li{padding:10px 100px; line-height:20px; overflow:hidden; zoom:1;}'
            +'ul.pop_lo_list li.spot_item{display:none;}'
            +'ul.pop_lo_list li input.us_name,ul.pop_lo_list li input.us_pwd,ul.pop_lo_list li input.us_pwd_panel,ul.pop_lo_list li input.us_spot{border:#d9d9d9 solid 1px; width:318px; padding:8px 10px; color:#666;}'
            +'ul.pop_lo_list li input.us_spot{width:130px;}'
            +'ul.pop_lo_list li a.lo_bnt{display:block; width:150px; height:40px; line-height:40px; text-align:center; color:#fff; background:#70c404; font-size:14px; text-decoration:none;}'
            +'ul.pop_lo_list li a.lo_bnt:hover{background:#6DB823;}'
            +'ul.pop_lo_list li a.close_btn{background:url(http://static.5sing.com/images/sns_icons.png) 0 -32px no-repeat; position:absolute; right:10px; top:10px; width:28px; height:28px; text-indent:-999px; overflow:hidden;}'
            +'ul.pop_lo_list li a.close_btn:hover{background-position:-32px -32px;}'
            +'ul.pop_lo_list li a.forget{color:#30aa00;}'
            +'ul.pop_lo_list li a.free_join{line-height:40px; color:#30aa00;}'
            +'ul.pop_lo_list li input.IsSave{margin-top:4px; _margin-top:0px; float:left;}'
            +'ul.pop_lo_list li span.errotip{position:absolute; left:100px; top:5px; color:#ff3000;}'
            +'ul.pop_lo_list li a.identifier{position:absolute; right:100px; cursor: hand; top:149px; width:140px; height:52px; overflow:hidden;}'
            +'ul.pop_lo_list li.pop_lo_copt{background:#f5f5f5; padding:30px 100px; margin-top:15px; line-height:32px; font-size:14px;}'
            +'ul.pop_lo_list li.pop_lo_copt a{width:32px; height:32px; background:url(http://static.5sing.com/images/sns_icons.png) no-repeat; text-indent:-999px; overflow:hidden; margin-left:10px; display:inline;}'
            +'ul.pop_lo_list li.pop_lo_copt a.kaixin{background-position:-128px 0;}'
            +'ul.pop_lo_list li.pop_lo_copt a.renren{background-position:-96px 0;}'
            +'ul.pop_lo_list li.pop_lo_copt a.tencent{background-position:-64px 0;}'
            +'ul.pop_lo_list li.pop_lo_copt a.weibo{background-position:-32px 0;}'
            +'ul.pop_lo_list li.pop_lo_copt a.qq{background-position:0 0;}</style>';
        var html = '<div class="pop_lo_bg">'
            + '<ul class="pop_lo_list">'
            + '<li><input type="text" class="us_name" value="通行证" onfocus="if(value==defaultValue){value=\'\';}" onBlur="if(!value){value=defaultValue;}"/></li>'
            + '<li><input type="text" class="us_pwd_panel" value="密码" onfocus="this.style.display=\'none\';this.parentElement.children.item(1).style.display=\'block\';this.parentElement.children.item(1).focus()"/>'
            +'<input type="password" class="us_pwd" value="" style="display:none;" onBlur="if(!value){this.style.display=\'none\';this.parentElement.children.item(0).style.display=\'block\';}" /></li>'
            + '<li class="spot_item">'
            + '<input type="text" class="us_spot" value="验证码" onfocus="if(value==defaultValue){value=\'\';}" onBlur="if(!value){value=defaultValue;}"/>'
            + '<a class="identifier" title="看不清楚？点击换一张"><img alt="" src="http://www.5sing.com/code"/></a>'
            + '</li>'
            + '<li>'
            + '<span class="lt"><input type="checkbox" class="IsSave" id="IsSave"/><label for="IsSave">记住我</label></span>'
            + '<em style="color:#FF0000; display: none;">&nbsp;&nbsp;建议在网吧或公共电脑上取消该选项。</em>'
            + '<a class="forget rt" href="http://www.5sing.com/getpass/" target="_blank" title="忘记密码">忘记密码</a>'
            + '<a href="javascript:;" class="close_btn" title="关闭">关闭</a>'
            + '<span class="errotip"></span>'
            + '</li>'
            + '<li>'
            + '<a class="lo_bnt lt" href="#" title="登录">登录</a>'
            + '<a class="free_join rt" href="http://www.5sing.com/reg/" target="_blank" title="注册">注册</a>'
            + '</li>'
            + '<li class="pop_lo_copt">'
            + '<span class="lt">使用合作账号登录</span>'
            + '<a class="kaixin rt" target="_blank" href="http://www.5sing.com/login?do=2&refUrl='+window.location.href+'" title="开心网">开心网</a>'
            + '<a class="renren rt" target="_blank" href="http://www.5sing.com/login?do=3&refUrl='+window.location.href+'" title="人人网">人人网</a>'
            + '<a class="tencent rt" target="_blank" href="http://www.5sing.com/login?do=4&refUrl='+window.location.href+'" title="腾讯微博">腾讯微博</a>'
            + '<a class="weibo rt" target="_blank" href="http://www.5sing.com/login?do=1&refUrl='+window.location.href+'" title="新浪微博">新浪微博</a>'
            + '<a class="qq rt" target="_blank" href="http://www.5sing.com/login?do=5&refUrl='+window.location.href+'" title="QQ">QQ</a>'
            + '</li>'
            + '</ul>'
            + '</div>';
        var loginBox = $(".pop_lo_bg");
        var loginBox_bg = $(".pop_lo_bg_bg");
        var logining = false;
        if(loginBox.length <= 0)
        {
            $("body").append(style + html);
            loginBox = $(".pop_lo_bg");
            $("body").append('<div class="pop_lo_bg_bg"></div>');
            loginBox_bg = $(".pop_lo_bg_bg");
            loginBox.hide();
            loginBox.find(".close_btn").click(function(){
                loginBox.animate({"opacity": 0}, 200,function(){
                    loginBox.hide();
                    loginBox_bg.hide();
                });
            });
            $(document).keydown(function(e){
                var key = (e.keyCode) || (e.which) || (e.charCode);
                if(key == 27)
                {
                    loginBox.animate({"opacity": 0}, 200,function(){
                        loginBox.hide();
                        loginBox_bg.hide();
                    });
                }
            });
            loginBox.find(".pop_lo_list > li > span.lt").hover(function(){
                $(this).next("em").show();
            },function(){
                $(this).next("em").hide();
            });
            loginBox.find(".identifier").click(function(){
                globals.$(this).find("img").attr("src", "http://www.5sing.com/code?" + (new Date()).getTime());
            });
            var us_name = loginBox.find(".us_name");
            var us_pwd = loginBox.find(".us_pwd");
            var us_spot = loginBox.find(".us_spot");
            var IsSave = loginBox.find(".IsSave");
            var errotip = loginBox.find(".errotip");
            loginBox.find(".lo_bnt").click(function(){
                if(!logining)
                {
                    logining = true;
                    var us_name_txt = us_name.val();
                    var us_pwd_txt = us_pwd.val();
                    var us_spot_txt = us_spot.val();
                    var isSave_val = IsSave.is(":checked") ? 1 : 0;
                    if(us_name_txt.length <=0)
                    {
                        errotip.html("请输入用户名");
                        logining = false;
                        return;
                    }
                    if(us_pwd_txt.length <=0)
                    {
                        errotip.html("请输入密码");
                        logining = false;
                        return;
                    }
                    var url = "http://service.5sing.com/user/login?jsoncallback=?";
                    $.getJSON(url, {username: us_name_txt, password: us_pwd_txt, code: us_spot_txt, isRemember: isSave_val}, function(res){
                        logining = false;
                        if(res.isSuccess)
                        {
                            if(typeof(callback) == "function")
                                callback(res.data);
                            loginBox.animate({"opacity": 0}, 200,function(){
                                loginBox.hide();
                                loginBox_bg.hide();
                            });
                            globals.UserStatus();
                        }
                        else
                        {
                            if(res.data.overLimit >= 3)
                                us_spot.parent().show();
                            errotip.html(res.message);
                        }
                    })
                }
            });
        }
        $.getJSON("http://service.5sing.com/user/limitTimes?jsoncallback=?", {}, function(res){
            if(res.limit >= 3)
                loginBox.find(".us_spot").parent().show();
            var height = globals.$(window).height();
            var width = globals.$(window).width();
            var top = parseInt((height - loginBox.height()) / 2) + globals.$(window).scrollTop();
            var left = parseInt((width - loginBox.width()) / 2) + globals.$(window).scrollLeft();
            loginBox_bg.show();
            loginBox.css({"opacity": 0, "top": top + "px", "left": left + "px"}).show().animate({"opacity": 1}, 200)
        });
    };
    $.userCard = function(cls){
        var sources = {
            "findUser": "http://service.5sing.com/user/find?jsonCallback=?",
            "addFriend": "http://service.5sing.com/relation/addFriend?jsonCallback=?",
            "removeFriend": "http://service.5sing.com/relation/removeFriend?jsonCallback=?"
        };
        var self = this;
        var loadingTemp = '<div class="sp_card_loading">'
            + '<img src="http://static.5sing.com/images/v2012/loading.gif" width="32" height="32" alt="正在加载中..." />'
            + '</div>' + '<b class="sp_caret sp_caret_out"></b><b class="sp_caret sp_caret_in"></b>';
        var userTemp = '<dl class="sp_card_view">' +
            '<dt><a href="http://www.5sing.com/{user.id}" target="_blank"><img src="{user.avatar}" border="0" width="48" height="48" /></a></dt>' +
            '<dd>' +
            '<a target="_blank" href="http://www.5sing.com/{user.id}">{user.nickname}</a><br />关注&nbsp;' +
            '<a target="_blank" href="http://www.5sing.com/{user.id}/friend/1.html">{user.totalfriends}</a>&nbsp;&nbsp;|&nbsp;&nbsp;粉丝&nbsp;' +
            '<a target="_blank" href="http://www.5sing.com/{user.id}/fans/1.html">{user.totalfans}</a>&nbsp;&nbsp;|&nbsp;&nbsp;人气&nbsp;{user.totalrq}</dd>' +
            '</dl>' +
            '<div class="sp_card_intro">{user.memo}</div>' +
            '<div class="sp_card_medal">' +
            '<ul>{user.special}</ul>' +
            '</div>' +
            '<div class="sp_card_follow"><span></span><a href="#" uid="{user.id}" class="sp_follow_bnt {user.follow}">{user.followText}</a></div>' +
            '<b class="sp_caret sp_caret_out"></b>' +
            '<b class="sp_caret sp_caret_in"></b>';
        var notFoundTemp = '<div class="sp_card_null"><p>没有找到相关信息</p><a target="_blank" href="http://sou.5sing.com/smember.aspx?key={user.search}">搜索该会员</a></div>' + '<b class="sp_caret sp_caret_out"></b><b class="sp_caret sp_caret_in"></b>';

        var closeTimer = null;
        var showTimer = null;

        var cardBg = $(".sp_card_bg");
        var cardContainer = $(".sp_card_bg > .sp_card");

        var init = function(){
            if ($(".sp_card_bg").length <= 0) {
                var style = '<style>' +
                    '.sp_card_bg{ position:absolute; top:0px; left:0px; color: #666666; font:12px/1.5 Tahoma,Helvetica,Arial,sans-serif; z-index:13010;}' +
                    '.sp_card_bg img{ border-style:none;}' +
                    '.sp_card_bg ul,.sp_card_bg li, .sp_card_bg dt, .sp_card_bg dd, .sp_card_bg dl { margin: 0; padding: 0; list-style:none;}' +
                    '.sp_card{text-align:left; border:1px solid #CFCFCF;background:white;position:relative;box-shadow:0px 0px 2px 2px rgba(0, 0, 0, 0.1); width:330px; padding:15px; height:148px;}' +
                    '.sp_card::after{content:".";height:0;display:block;visibility:hidden;clear:both;font-size:0;}' +
                    '.sp_card a:link,.sp_card a:visited{ color:#6DB823;}' +
                    '.sp_card_view{ height:52px; overflow:hidden;}' +
                    '.sp_card_view dt{ float:left; width:48px; margin:4px 11px 0 0;}' +
                    '.sp_card_view dd{ float:left; color:#aaa; line-height:2.3;}' +
                    '.sp_card_intro{ width:330px;word-wrap:break-word;word-break:normal;overflow:hidden; padding:15px 0 12px; height:18px; line-height:18px;}' +
                    '.sp_card_intro em{color:#aaa;}' +
                    '.sp_card_medal{ height:20px; overflow:hidden; padding-bottom:5px;}' +
                    '.sp_card_medal ul{ overflow:hidden; zoom:1;}' +
                    '.sp_card_medal ul li{ float:left; margin-right:5px;}' +
                    '.sp_card_follow{ overflow:hidden; zoom:1;}' +
                    '.sp_card_bg .sp_follow_bnt{ line-height:24px; background:#6DB823; height:24px; padding:0 15px; display:block; float:right;}' +
                    '.sp_card_bg .sp_card .sp_follow_bnt:link,.sp_card_bg .sp_card .sp_follow_bnt:visited{ color:#fff;}' +
                    '.sp_card_bg .sp_follow_bnt:hover{ background:#73C325; text-decoration:none;}' +
                    '.sp_caret_in,.sp_caret_out{ position:absolute;border-style:solid dashed dashed dashed; display:block;font-family:simsun;width:0px;height:0px;_line-height:0;font-size:0;}' +
                    '.sp_caret_in{left:29px;top:auto;bottom:-7px;border-width:7px 6px 0 6px;border-color:#fff transparent transparent transparent; z-index:2;}' +
                    '.sp_caret_out{ z-index:1;border-width:8px 7px 0 7px;border-color:#CFCFCF transparent transparent transparent;bottom:-8px; left:28px;}' +
                    '.sp_card_loading{ width:32px; margin:0 auto; text-align:center; padding:60px 0 0 0;}' +
                    '.sp_card_bg .sp_unfollow_bnt{ background:#aaa;}' +
                    '.show_userCard_link img{display:block;}' +
                    '.sp_card_null{ text-align:center; color:#666; padding-top:40px;}' +
                    '.sp_card_null p{font-size:18px; font-family:"Microsoft Yahei",微软雅黑 ; padding-bottom:10px;}' +
                    '.sp_card_null a{ display:block; width:120px; height:36px; line-height:36px; margin:0 auto; font-size:14px;}' +
                    '.sp_card_null a:link,.sp_card_null a:visited{ color:#fff; background:#74bd53;}' +
                    '.sp_card_null a:hover{ background:#4a9f24; text-decoration:none;}' +
                    '</style>';
                $(style).appendTo("body");
                var html = '<div class="sp_card_bg" style="display:none; height:180px;">' +
                    '<div class="sp_card">' +
                    '</div>' +
                    '</div>';
                $(html).appendTo("body");
                cardBg = $(".sp_card_bg");
                cardContainer = $(".sp_card_bg > .sp_card");
            }
            $(cls).live({
                "mouseover": function(){
                    if (closeTimer != null) {
                        clearTimeout(closeTimer);
                        closeTimer = null;
                    }
                    if (showTimer != null) {
                        clearTimeout(showTimer);
                        showTimer = null;
                    }
                    var THIS = this;
                    showTimer = setTimeout(function () {
                        cardContainer.html(loadingTemp);
                        var ct = $(THIS).height();
                        var ucH = 180;
                        var offset = $(THIS).offset();
                        var st = 0;
                        var sl = 0;
                        if (document.documentElement) {
                            st = parseInt(document.documentElement.scrollTop);
                            sl = parseInt(document.documentElement.scrollLeft);
                        }
                        if (st <= 0 && document.body) {
                            st = parseInt(document.body.scrollTop);
                        }
                        if (sl <= 0 && document.body) {
                            sl = parseInt(document.body.scrollLeft);
                        }
                        var tt = offset.top - st;
                        var bt = $(window).height() - offset.top + st - $(THIS).height();
                        var ll = offset.left;
                        var rl = $(window).width() + sl - offset.left;
                        var fixed = 0;
                        if (rl < 362) {
                            fixed = 362 - rl;
                        }
                        var halfW = parseInt($(THIS).width() / 2);
                        if (isNaN(halfW))
                            halfW = 28;
                        if (tt < ucH && bt >= ucH) {
                            $(".sp_card_bg .sp_caret").eq(0).css({ "border-width": "0 8px 7px 7px", "bottom": (ucH - 2) + "px", "left": (halfW - 8 + fixed) + "px", "border-color": "transparent transparent #CFCFCF transparent", "border-style": "dashed dashed solid dashed" });
                            $(".sp_card_bg .sp_caret").eq(1).css({ "border-width": "0 6px 7px 6px", "bottom": (ucH - 2) + "px", "left": (halfW - 7 + fixed) + "px", "border-color": "transparent transparent #fff transparent", "border-style": "dashed dashed solid dashed" });
                            cardBg.css({ left: offset.left - fixed, top: offset.top + ct + 8 }).show();
                        }
                        else {
                            $(".sp_card_bg .sp_caret").eq(0).css({ "border-width": "8px 7px 0 7px", "bottom": "-8px", "left": (halfW - 8 + fixed) + "px", "border-color": "#CFCFCF transparent transparent transparent", "border-style": "solid dashed dashed dashed" });
                            $(".sp_card_bg .sp_caret").eq(1).css({ "border-width": "7px 6px 0 6px", "bottom": "-7px", "left": (halfW - 7 + fixed) + "px", "border-color": "#fff transparent transparent transparent", "border-style": "solid dashed dashed dashed" });
                            cardBg.css({ left: offset.left - fixed, top: offset.top - ucH - 8 }).show();
                        }
                        var nnOrId = $(THIS).attr("uid");
                        if (typeof nnOrId == "undefined" || $("body").data("html_" + nnOrId) == undefined) {
                            var href = decodeURIComponent($(THIS).attr("href"));
                            var nnIndex = href.indexOf("?nickname=");
                            if (nnIndex == -1) {
                                nnIndex = href.indexOf("http://www.5sing.com/");
                                if(nnIndex != -1)
                                {
                                    href = href.replace("http://www.5sing.com/", "");
                                    var endIndex = href.indexOf(".");
                                    if (endIndex != -1) {
                                        nnOrId = href.substring(0, endIndex);
                                    }
                                    else
                                        nnOrId = href;
                                }
                                else
                                    nnOrId = $(THIS).text();
                            }
                            else
                                nnOrId = href.substring(nnIndex + 11);
                            $.getJSON(sources.findUser, { userArg: nnOrId, special: 1, withLi: 1}, function (res) {
                                var resHtml = "";
                                if(res.isSuccess)
                                {
                                    $(THIS).attr("uid", res.data.userid);
                                    var memo = res.data.memo != null && res.data.memo.length > 0 ? (res.data.memo.length <= 25 ? res.data.memo : (res.data.memo.substring(0, 25) + "...")) : "<em>暂无介绍</em>";
                                    var followText = "+&nbsp;关注";
                                    if(res.data.follow == 1)
                                        followText = "已关注&nbsp;|&nbsp;取消";
                                    else if(res.data.follow == 2)
                                        followText = "相互关注&nbsp;|&nbsp;取消";
                                    resHtml = userTemp.replace(/{user.id}/g, res.data.userid)
                                        .replace(/{user.avatar}/g, res.data.avatar.replace(/(\.jpg|\.jpeg|\.png|\.gif)$/i, "_48_48$1"))
                                        .replace(/{user.nickname}/g, res.data.nickname)
                                        .replace(/{user.totalfriends}/g, res.data.totalfriend)
                                        .replace(/{user.totalfans}/g, res.data.totalfans)
                                        .replace(/{user.totalrq}/g, res.data.totalrq)
                                        .replace(/{user.memo}/g, memo).replace(/{user.special}/g, res.data.special)
                                        .replace(/{user.follow}/g, res.data.follow >= 1 ? " sp_unfollow_bnt" : "")
                                        .replace(/{user.followText}/g, followText);
                                    $("body").data("html_" + res.data.userid, resHtml);
                                }
                                else{
                                    $(THIS).attr("uid", nnOrId);
                                    resHtml = notFoundTemp.replace("{user.search}", encodeURIComponent(nnOrId));
                                    $("body").data("html_" + nnOrId, resHtml);
                                }
                                cardContainer.html(resHtml);
                                if (tt < ucH && bt >= ucH) {
                                    $(".sp_card_bg .sp_caret").eq(0).css({ "border-width": "0 8px 7px 7px", "bottom": (ucH - 2) + "px", "left": (halfW - 8 + fixed) + "px", "border-color": "transparent transparent #CFCFCF transparent", "border-style": "dashed dashed solid dashed" });
                                    $(".sp_card_bg .sp_caret").eq(1).css({ "border-width": "0 6px 7px 6px", "bottom": (ucH - 2) + "px", "left": (halfW - 7 + fixed) + "px", "border-color": "transparent transparent #fff transparent", "border-style": "dashed dashed solid dashed" });
                                    cardBg.css({ left: offset.left - fixed, top: offset.top + ct + 8 }).show();
                                }
                                else {
                                    $(".sp_card_bg .sp_caret").eq(0).css({ "border-width": "8px 7px 0 7px", "bottom": "-8px", "left": (halfW - 8 + fixed) + "px", "border-color": "#CFCFCF transparent transparent transparent", "border-style": "solid dashed dashed dashed" });
                                    $(".sp_card_bg .sp_caret").eq(1).css({ "border-width": "7px 6px 0 6px", "bottom": "-7px", "left": (halfW - 7 + fixed) + "px", "border-color": "#fff transparent transparent transparent", "border-style": "solid dashed dashed dashed" });
                                    cardBg.css({ left: offset.left - fixed, top: offset.top - ucH - 8 }).show();
                                }
                            });
                        }
                        else{
                            cardContainer.html($("body").data("html_" + nnOrId));
                            if (tt < ucH && bt >= ucH) {
                                $(".sp_card_bg .sp_caret").eq(0).css({ "border-width": "0 8px 7px 7px", "bottom": (ucH - 2) + "px", "left": (halfW - 8 + fixed) + "px", "border-color": "transparent transparent #CFCFCF transparent", "border-style": "dashed dashed solid dashed" });
                                $(".sp_card_bg .sp_caret").eq(1).css({ "border-width": "0 6px 7px 6px", "bottom": (ucH - 2) + "px", "left": (halfW - 7 + fixed) + "px", "border-color": "transparent transparent #fff transparent", "border-style": "dashed dashed solid dashed" });
                                cardBg.css({ left: offset.left - fixed, top: offset.top + ct + 8 }).show();
                            }
                            else {
                                $(".sp_card_bg .sp_caret").eq(0).css({ "border-width": "8px 7px 0 7px", "bottom": "-8px", "left": (halfW - 8 + fixed) + "px", "border-color": "#CFCFCF transparent transparent transparent", "border-style": "solid dashed dashed dashed" });
                                $(".sp_card_bg .sp_caret").eq(1).css({ "border-width": "7px 6px 0 6px", "bottom": "-7px", "left": (halfW - 7 + fixed) + "px", "border-color": "#fff transparent transparent transparent", "border-style": "solid dashed dashed dashed" });
                                cardBg.css({ left: offset.left - fixed, top: offset.top - ucH - 8 }).show();
                            }
                        }
                    }, 500);
                },
                "mouseout": function(){
                    closeTimer = setTimeout(function () {
                        cardBg.hide();
                        if (showTimer != null) {
                            clearTimeout(showTimer);
                            showTimer = null;
                        }
                    }, 400);
                }
            });
            cardBg.hover(function () {
                if (closeTimer != null) {
                    clearTimeout(closeTimer);
                    closeTimer = null;
                }
            }, function () {
                closeTimer = setTimeout(function () {
                    cardBg.hide();
                    if (showTimer != null) {
                        clearTimeout(showTimer);
                        showTimer = null;
                    }
                }, 400);
            });
            $(".sp_card_bg .sp_card_follow a").live("click", function(){
                var callback = function () {
                };
                var source = "";
                var TTHis = this;
                var userid = $(TTHis).attr("uid");
                if($(this).hasClass("sp_unfollow_bnt"))
                {
                    source = sources.removeFriend;
                    callback = function () {
                        $(TTHis).removeClass("sp_unfollow_bnt").html("+&nbsp;关注");
                        $("body").data("html_" + userid, cardContainer.html());
                    };
                }
                else{
                    source = sources.addFriend;
                    callback = function (res) {
                        if(res.isSuccess)
                        {
                            $(TTHis).addClass("sp_unfollow_bnt").html("已关注&nbsp;|&nbsp;取消");
                            $("body").data("html_" + userid, cardContainer.html());
                        }
                        else
                        {
                            $(TTHis).siblings("span").html(res.message).show();
                        }
                    };
                }
                $.getJSON(source, { UserID: userid }, callback);
            });
        };
        init();
    };
    $.fn.autoResize = function(options) {
        var settings = $.extend({
            onResize : function(){},
            animate : true,
            animateDuration : 150,
            animateCallback : function(){},
            extraSpace : 20,
            limit: 10000
        }, options);

        this.filter('textarea').each(function(){
            var textarea = $(this).css({resize:'none','overflow-y':'hidden'}),
                origHeight = textarea.height(),
                clone = (function(){
                    var props = ['height','width','lineHeight','textDecoration','letterSpacing'],
                        propOb = {};
                    $.each(props, function(i, prop){
                        propOb[prop] = textarea.css(prop);
                    });
                    return textarea.clone().removeAttr('id').removeAttr('name').css({
                        position: 'absolute',
                        top: 0,
                        left: -9999
                    }).css(propOb).attr('tabIndex','-1').insertBefore(textarea);

                })(),
                lastScrollTop = null,
                updateSize = function() {
                    clone.height(0).val($(this).val()).scrollTop(10000);
                    var scrollTop = Math.max(clone.scrollTop(), origHeight) + settings.extraSpace,
                        toChange = $(this).add(clone);
                    if (lastScrollTop === scrollTop) { return; }
                    lastScrollTop = scrollTop;
                    if ( scrollTop >= settings.limit ) {
                        $(this).css('overflow-y','hidden');
                        return;
                    }
                    settings.onResize.call(this);
                    settings.animate && textarea.css('display') === 'block' ?
                        toChange.stop().animate({height:scrollTop}, settings.animateDuration, settings.animateCallback)
                        : toChange.height(scrollTop);
                };
            textarea
                .unbind('.dynSiz')
                .bind('keyup.dynSiz', updateSize)
                .bind('keydown.dynSiz', updateSize)
                .bind('change.dynSiz', updateSize);

        });
        return this;
    };
    $.fn.textareaCur = function(){
        var range = null;
        var textareaCur = {
            'getInputSelection': function (el, range) {

                var start = 0,
                    end = 0,
                    normalizedValue,
                    textInputRange,
                    len,
                    endRange;

                if (typeof el.selectionStart === "number" && typeof el.selectionEnd === "number") {
                    start = el.selectionStart;
                    end = el.selectionEnd;
                }
                else {
                    !range && (range = document.selection.createRange());
                    if (range && range.parentElement() === el) {
                        len = el.value.length;
                        normalizedValue = el.value.replace(/\r\n/g, "\n");

                        textInputRange = el.createTextRange();
                        textInputRange.moveToBookmark(range.getBookmark());

                        endRange = el.createTextRange();
                        endRange.collapse(false);

                        if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
                            start = end = len;
                        } else {
                            start = -textInputRange.moveStart("character", -len);
                            start += normalizedValue.slice(0, start).split("\n").length - 1;

                            if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) {
                                end = len;
                            } else {
                                end = -textInputRange.moveEnd("character", -len);
                                end += normalizedValue.slice(0, end).split("\n").length - 1;
                            }
                        }
                    }
                }

                return {
                    start: start,
                    end: end
                };
            },

            'setInputSelection': function (el, startOffset, endOffset) {
                if (typeof el.selectionStart === "number" && typeof el.selectionEnd === "number") {
                    el.selectionStart = startOffset;
                    el.selectionEnd = endOffset;
                } else {
                    var range = el.createTextRange();
                    var startCharMove = this.offsetTo(el, startOffset);
                    range.collapse(true);
                    if (startOffset === endOffset) {
                        range.move("character", startCharMove);
                    } else {
                        range.moveEnd("character", this.offsetTo(el, endOffset));
                        range.moveStart("character", startCharMove);
                    }
                    range.select();
                }
            },

            'offsetTo': function (el, offset) {
                return offset - (el.value.slice(0, offset).split("\r\n").length - 1);
            },
            'getContentPrex':function(textBox) {
                var text = textBox.value;
                var matches = text.match(/^(回复\s.+[:：]{1})/);
                if (!!matches) {
                    return matches[1];
                }
                return "";
            }
        };
        var textareaEvents = {
            "focus": function(){
                var prex = textareaCur.getContentPrex(this);
                if (!!prex)
                    textareaCur.setInputSelection(this, prex.length, $(this).val().length)
            },
            "key":function(e){
                var keyCode = 0;
                var prex = textareaCur.getContentPrex(this);
                if (!!prex) {
                    var pos = textareaCur.getInputSelection(this, range);
                    if (window.event)
                        keyCode = e.keyCode;
                    else
                        keyCode = e.which;
                    if (keyCode == 8) {
                        if (prex == $(this).val() || pos.start == prex.length)
                            return false;
                    }
                    if (pos.start < prex.length) {
                        var start = prex.length;
                        var end = pos.end;
                        if (end < start)
                            end = start;
                        textareaCur.setInputSelection(this, start, end);
                    }
                }
            },
            "mouse":function(){
                var prex = textareaCur.getContentPrex(this);
                if (!!prex) {
                    var pos = textareaCur.getInputSelection(this, range);
                    var start = pos.start, end = pos.end;
                    if (start < prex.length && end < prex.length)
                        start = end = $(this).val().length;
                    else if (start < prex.length)
                        start = prex.length;
                    else if (end < prex.length)
                        end = prex.length;
                    if (start > end)
                        start = end;
                    textareaCur.setInputSelection(this, start, end);
                }
            }
        };
        $(this).unbind(".textareacur")
            .bind("focus.textareacur", textareaEvents.focus)
            .bind("mousedown.textareacur", textareaEvents.mouse)
            .bind("mouseup.textareacur", textareaEvents.mouse)
            .bind("keydown.textareacur", textareaEvents.key)
            .bind("keyup.textareacur", textareaEvents.key);
        return this;
    };
    $.ksPlugin = {
        alert:function(options,callback) {
            var id = 'ksPlugin-alert-' + new Date().getTime();
            var defaults = {title : '温馨提示',yes:'确认',multi:false};
            options = $.extend(true, {}, defaults, options);
            $.ksPlugin.showBackGround();

            var html ='<div class="tip_box w400_box"  id="'+id+'">'
                +'<div class="pop_tit">'
                +'<span class="lt">'+options.title+'</span>'
                +'<a href="javascript:;" class="rt a_btn btn_close" title="关闭"><b class="m_btn">关闭</b></a>'
                +'</div>'
                +'<dl class="c_wap">'
                +'<dt>';
            if(options.multi)
                html+='<p>'+options.content+'</p>';
            else
                html+='<p class="line">'+options.content+'</p>';
            html+='</dt>'
                +'<dd class="c_wap act_btns">'
                +'<a class="a_btn btn_yes" href="javascript:;">'+options.yes+'</a>'
                +'</dd>'
                +'</dl>'
                +'</div>';
            $('body').append(html);
            $('#'+id).find('.btn_yes').click(function(){
                $('#'+id).remove();
                $.ksPlugin.hideBackGround();
                if(callback)
                    callback();
            });
            $('#'+id).find('.btn_close').click(function(){
                $('#'+id).remove();
                $.ksPlugin.hideBackGround();
                if(callback)
                    callback();
            });
        },
        confirm:function(options,callback,callbackno)
        {
            var id = 'mb-' + new Date().getTime();
            var defaults = {title : '温馨提示',yes:'确认',no:'取消',icon:'',multi:false};
            options = $.extend(true, {}, defaults, options);
            $.ksPlugin.showBackGround();
            var html='';
            if(options.icon=='')
            {
                html='<div class="tip_box w400_box" id="'+id+'" style="display:;">'+
                    '<div class="pop_tit">'+
                    '<span class="lt">'+options.title+'</span>'+
                    '<a href="javascript:;" class="rt a_btn btn_close" title="关闭"><b class="m_btn">关闭</b></a>'+
                    '</div>'+
                    '<dl class="c_wap">'+
                    '<dt>';
                if(options.multi)
                    html+='<p>'+options.content+'</p>';
                else
                    html+='<p class="line">'+options.content+'</p>';

                html+='</dt>'+
                    '<dd class="c_wap act_btns confirm">'+
                    '<a href="javascript:;" class="a_btn btn_yes">'+options.yes+'</a>'+
                    '<a href="javascript:;" class="a_btn btn_no">'+options.no+'</a>'+
                    '</dd>'+
                    '</dl>'+
                    '</div>';


                $('body').append(html);
            }
            else
            {

                html ='<div class="tip_box s_icon"  id="'+id+'">'+
                    '<div class="pop_tit">'+
                    '<span class="lt">'+options.title+'</span>'+
                    '<a href="javascript:;" class="rt a_btn btn_close" title="关闭"><b class="m_btn">关闭</b></a>'+
                    '</div>'+
                    '<dl class="c_wap ct_com">'+
                    '<dt>';
                var classname = 'tips';
                classname+=' ' + options.icon;
                if(options.multi)
                    classname+=' line';
                if(options.icon=='')
                {
                    html+='<p class="'+classname+'">'+options.content+'</p>';
                }
                else

                {
                    html+='<p class="'+classname+'"><i></i>'+options.content+'</p>';
                }
                html+='</dt>'+
                    '<dd class="c_wap act_btns">'+
                    '<a href="javascript:;" class="a_btn btn_yes">'+options.yes+'</a>'+
                    '<a href="javascript:;" class="a_btn btn_no">'+options.no+'</a>'+
                    '</dd>'+
                    '</dl>'+
                    '</div>';
                $('body').append(html);
            }
            $('#'+id).find('.btn_yes').click(function(){
                //options.callback;
                $('#'+id).remove();
                $.ksPlugin.hideBackGround();
                if(callback)
                    callback();
            });
            $('#'+id).find('.btn_no').click(function(){
                $('#'+id).remove();
                $.ksPlugin.hideBackGround();
                if(callbackno)
                    callbackno();
            });
            $('#'+id).find('.btn_close').click(function(){
                $('#'+id).remove();
                $.ksPlugin.hideBackGround();
                if(callbackno)
                    callbackno();
            });
        },
        success:function(message, delay, reload)
        {
            var id = 'ksPlugin-success-' + new Date().getTime();
            var html = '<div class="tip_box tip_com" id="'+id+'">'
                +'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tbody><tr><td class="t_icon"><i></i></td><td class="t_cons">'+message+'</td></tr></tbody></table>'
                +'</div>';

            $('body').append(html);
            delay = delay==undefined?2000:delay;
            setTimeout(function(){
                $("#"+id).remove();
                if(reload === true){
                    window.location.reload();
                }
                else if(!!reload){
                    window.location.href = reload;
                }
            },delay);
        },
        showLoading:function(id,message,delay){
            delay = delay == undefined?500:delay;

            var obj = setTimeout(function(){
                var html = '<div class="tip_box tip_loding" id="'+id+'">'
                    +'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tbody><tr><td class="t_icon"><i></i></td><td class="t_cons">'+message+'</td></tr></tbody></table></div>'
                    +'</div>';
                $('body').append(html);
            },delay);
            return obj;
        },
        hideLoading:function(id,obj)
        {
            if(obj!=null)
                clearTimeout(obj);
            if($('#'+id).length>0)
                $('#'+id).remove();
        },
        faild:function(message, delay, reload){
            var id = 'ksPlugin-faild-' + new Date().getTime();
            var html = '<div class="tip_box tip_del" id="'+id+'">'
                +'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tbody><tr><td class="t_icon"><i></i></td><td class="t_cons">'+message+'</td></tr></tbody></table></div>'
                +'</div>';
            $('body').append(html);
            delay = delay==undefined?2000:delay;
            setTimeout(function(){
                $("#"+id).remove();
                if(reload === true){
                    window.location.reload();
                }
                else if(!!reload){
                    window.location.href = reload;
                }
            },delay);
        },
        tips:function(message, delay, reload){
            var id = 'ksPlugin-normal-' + new Date().getTime();
            var html = '<div class="tip_box tip_normal" id="'+id+'">'
                +'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tbody><tr><td class="t_icon"></td><td class="t_cons">'+message+'</td></tr></tbody></table>'
                +'</div>';
            $('body').append(html);
            delay = delay==undefined?2000:delay;
            $("#"+id).animate();
            setTimeout(function(){
                $("#"+id).remove();
                if(reload === true){
                    window.location.reload();
                }
                else if(!!reload){
                    window.location.href = reload;
                }
            },delay);
        },
        showBackGround:function()
        {
            if($('.pop_lo_bg_bg').length==0)
            {
                var style = "<style>.pop_lo_bg_bg {background:rgba(0, 0, 0, .5); background:#000\9; opacity:0.5\0;position:fixed;width:100%;height:100%;top:0;left: 0;display:block;filter: Alpha(opacity=50);z-index: 11000;_position: absolute;_height: expression(document.body.clientHeight+'px');}"
                    +".tip_confirm{position:fixed; top:50%; left:50%; margin-left:-200px; margin-top:-75px; width:400px; background:#fff; z-index:11001; _top:expression(documentElement.scrollTop+190);_position:absolute; _bottom:auto;}"
                    +"*html{background-image:url(about:blank);background-attachment:fixed;}"
                    +".tip_confirm .tip_tit{height:40px; line-height:40px; background:#74bd52; border-bottom:#5eb13f solid 1px; color:#fff; font-size:16px; padding:0 10px;}"
                    +".tip_confirm .tip_conbox{border:#e4e4e4 solid 1px; border-top:none; padding:10px; zoom:1;}"
                    +".tip_confirm .tip_conbox p{font-weight:bold; text-align:center; font-size:14px; height:60px; line-height:40px;}"
                    +".tip_confirm .tip_conbox a.lt:link,.tip_confirm .tip_conbox a.lt:visited{width:82px; height:30px; line-height:30px; text-align:center; text-decoration:none; color:#fff; display:inline;}"
                    +".tip_confirm .tip_conbox a.cf_btn{margin-left:95px; background:#74bd54;}"
                    +".tip_confirm .tip_conbox a.back_btn{margin-left:20px; background:#bfc1cd;}"
                    +".tip_confirm .tip_conbox a.cf_btn:hover{background:#ff3000;}"
                    +".tip_confirm .tip_conbox a.back_btn:hover{background:#a6a8b3;}</style>";
                $('head').append(style);
                $('body').append('<div class="pop_lo_bg_bg" style="display: none;"></div>');
            }
            $('.pop_lo_bg_bg').show();
        },
        hideBackGround:function()
        {
            $('.pop_lo_bg_bg').hide();
        },
        isPicUrl:function(url){
            var reg = /^(http:\/\/|https:\/\/).+(\.jpg|\.png|\.gif)$/i;
            if(url.match(reg))
                return true;
            return false;
        },
        isUrl:function(url){
            var reg = /^(http:\/\/|https:\/\/).+/i;
            if(url.match(reg))
                return true;
            return false;
        }
    };
    $.fn.singSimpleEdit = function(options) {
        var defaults = {
            title:'',
            id: '',
            name: '',
            padding:'20px',
            pic:true,
            link:true
        };
        var opts = $.extend(defaults, options);
        if(defaults.id.length == 0||defaults.name.length == 0)
        {
            $(this).html('初始化编辑器失败，请输入编辑器标题、ID以及名称');
            return false;
        }
        var html='';
        if(defaults.title.length > 0)
        {
            html = '<div class="edit_box">';
            html += '<h3>' + defaults.title + '</h3>';

        }
        else
        {
            html = '<div class="edit_box" style="padding-top:'+defaults.padding+'">';
        }
        html += '<div class="edit_tool">';
        html += '<ul>';
        if(defaults.pic)
            html += '<li class="edit_tool_pic"><a href="javascript:void(0)">添加图片</a></li>';
        if(defaults.link)
            html += '<li class="edit_tool_link"><a href="javascript:void(0)">添加链接</a></li>';
        html += '</ul>';
        //html += '<p><a href="http://www.5sing.com/help/detail-192.html" target="_blank">如何使用？</a></p>';
        html += '</div>';
        html += '<textarea style="resize:none;" class="up_text" id="' + opts.id + '" name="' + opts.name + '" cols="45" rows="4">' + $(this).text() + '</textarea>';
        html += '</div>';
        $(this).html(html);
        var obj = $(this);
        if($(this).find('.edit_tool_pic a').length>0)
        {
            $(this).find('.edit_tool_pic a').click(function(){
                $(".add_supp_title").remove();
                $(".add_supp_img").remove();
                var id = 'addPic-'+(new Date()).getTime();
                var picHtml = '<div id="'+id+'" class="pop_box add_supp_img" style="display:;">';
                picHtml+='<div class="pop_tit"><span>添加图片</span><a href="javascript:void(0)" class="rt a_btn"><b class="m_btn">关闭</b></a></div>';
                picHtml+='<div class="c_wap ct_com">';
                picHtml+='<dl>';
                picHtml+='<dd><input class="picurl" type="text" value="请输入图片地址"></dd>';
                picHtml+='</dl>';
                picHtml+='<div class="c_wap act_btns">';
                picHtml+='<table cellpadding="0" cellspacing="0" border="0" width="100%" height="40px">';
                picHtml+='<tbody><tr>';
                picHtml+='<td class="tip_txt">图片地址格式如：<br>http://static.5sing.com/images/logo-help.jpg</td>';
                picHtml+='<td><a href="javascript:void(0)" class="a_btn a_btn_add">确认</a></td>';
                picHtml+='</tr>';
                picHtml+='</tbody></table>';
                picHtml+='</div>';
                picHtml+='</div>';
                picHtml+='</div>';
                $(obj).find('.edit_box').append(picHtml);
                $("#"+id).find(".m_btn").click(function(){
                    $("#"+id).remove();
                });
                $("#"+id).find(".picurl").focus(function(){
                    $("#"+id).find(".picurl").parent().removeClass("error_tip");
                    $("#"+id).find(".tip_txt").removeClass('error_txt');
                    $("#"+id).find(".tip_txt").html('图片地址格式如：<br>http://static.5sing.com/images/logo-help.jpg');
                    if($(this).val()=='请输入图片地址')
                        $(this).val('');
                });
                $("#"+id).find(".picurl").blur(function(){
                    if(!$.ksPlugin.isPicUrl($("#"+id).find(".picurl").val()))
                    {
                        $("#"+id).find(".picurl").parent().addClass("error_tip");
                        $("#"+id).find(".tip_txt").addClass("error_txt");
                        $("#"+id).find(".tip_txt").html('请输入有效图片地址如：<br>http://static.5sing.com/images/logo-help.jpg');
                    }
                    if($(this).val()=='')
                        $(this).val('请输入图片地址');
                });
                $("#"+id).find(".a_btn_add").click(function(){
                    if($.ksPlugin.isPicUrl($("#"+id).find(".picurl").val()))
                    {
                        $("#"+id).find(".picurl").parent().removeClass("error_tip");
                        $("#"+id).find(".tip_txt").removeClass('error_txt');
                        $("#"+id).find(".tip_txt").html('图片地址格式如：<br>http://static.5sing.com/images/logo-help.jpg');
                        $(obj).find('.up_text').val($(obj).find('.up_text').val() + '[img]'+$("#"+id).find(".picurl").val()+'[/img]\r\n');
                        $("#"+id).remove();
                    }
                    else
                    {
                        $("#"+id).find(".picurl").parent().addClass("error_tip");
                        $("#"+id).find(".tip_txt").addClass("error_txt");
                        $("#"+id).find(".error_txt").html('请输入有效图片地址如：<br>http://static.5sing.com/images/logo-help.jpg');
                    }
                });
                //$(obj).find('.up_text').val($(obj).find('.up_text').val() + '[img]图片地址[/img]');
            });
        }
        if($(this).find('.edit_tool_link a').length>0)
        {
            $(this).find('.edit_tool_link a').click(function(){
                $(".add_supp_title").remove();
                $(".add_supp_img").remove();
                var id = 'addLink-'+(new Date()).getTime();
                var linkHtml = '<div class="pop_box add_supp_title" id="' + id + '" style="display:;">';
                linkHtml+='<div class="pop_tit"><span>添加链接</span><a href="javascript:void(0)" class="rt a_btn"><b class="m_btn">关闭</b></a></div>';
                linkHtml+='<div class="c_wap ct_com">';
                linkHtml+='<dl>';
                linkHtml+='<dt><input class="linkTitle" type="text" value="请输入标题内容"></dt>';
                linkHtml+='<dd><input class="linkUrl" type="text" value="请输入链接地址"></dd>';
                linkHtml+='</dl>';
                linkHtml+='<div class="act_btns">';
                linkHtml+='<table cellpadding="0" cellspacing="0" border="0" width="100%" height="40px">';
                linkHtml+='<tbody><tr>';
                linkHtml+='<td class="tip_txt">链接格式如：<br>http://www.5sing.com</td>';
                linkHtml+='<td><a href="javascript:void(0)" class="a_btn a_btn_add">确认</a></td>';
                linkHtml+='</tr>';
                linkHtml+='</tbody></table>';
                linkHtml+='</div>';
                linkHtml+='</div>';
                linkHtml+='</div>';
                $(obj).find('.edit_box').append(linkHtml);
                $("#"+id).find(".m_btn").click(function(){
                    $("#"+id).remove();
                });

                $("#"+id).find(".linkTitle").focus(function(){
                    $("#"+id).find(".linkTitle").parent().removeClass("error_tip");
                    $("#"+id).find(".tip_txt").removeClass('error_txt');
                    $("#"+id).find(".tip_txt").html('');
                    if($(this).val()=='请输入标题内容')
                        $(this).val('');
                });
                $("#"+id).find(".linkTitle").blur(function(){
                    if($.trim($("#"+id).find(".linkTitle").val()).length==0)
                    {
                        $("#"+id).find(".linkTitle").parent().addClass("error_tip");
                        $("#"+id).find(".tip_txt").addClass("error_txt");
                        $("#"+id).find(".tip_txt").html('请输入标题内容');
                        $(this).val('请输入标题内容');
                    }
                    else if($.trim($("#"+id).find(".linkTitle").val()).trueLength()>40){
                        $("#"+id).find(".linkTitle").parent().addClass("error_tip");
                        $("#"+id).find(".tip_txt").addClass("error_txt");
                        $("#"+id).find(".tip_txt").html('标题内容超过20个字');
                    }
                });

                $("#"+id).find(".linkUrl").focus(function(){
                    $("#"+id).find(".linkUrl").parent().removeClass("error_tip");
                    $("#"+id).find(".tip_txt").removeClass('error_txt');
                    $("#"+id).find(".tip_txt").html('链接格式如：<br>http://www.5sing.com');
                    if($(this).val()=='请输入链接地址')
                        $(this).val('');
                });
                $("#"+id).find(".linkUrl").blur(function(){
                    if($.trim($("#"+id).find(".linkUrl").val()).length==0)
                    {
                        $("#"+id).find(".linkUrl").parent().addClass("error_tip");
                        $("#"+id).find(".tip_txt").addClass("error_txt");
                        $("#"+id).find(".tip_txt").html('请输入链接地址');
                        $(this).val('请输入链接地址');
                    }
                    else if(!$.ksPlugin.isUrl($.trim($("#"+id).find(".linkUrl").val()))){
                        $("#"+id).find(".linkUrl").parent().addClass("error_tip");
                        $("#"+id).find(".tip_txt").addClass("error_txt");
                        $("#"+id).find(".tip_txt").html('链接格式如：<br>http://www.5sing.com');
                    }

                });

                $("#"+id).find(".a_btn_add").click(function(){
                    var errorMessage = checkTitleUrl($("#"+id).find(".linkTitle").val(),$("#"+id).find(".linkUrl").val());
                    if(errorMessage=='')
                    {
                        $("#"+id).find(".linkTitle").parent().removeClass("error_tip");
                        $("#"+id).find(".linkUrl").parent().removeClass("error_tip");
                        $("#"+id).find(".tip_txt").removeClass('error_txt');
                        $("#"+id).find(".tip_txt").html('链接格式如：<br>http://www.5sing.com');
                        $(obj).find('.up_text').val($(obj).find('.up_text').val() + '[url='+$("#"+id).find(".linkUrl").val()+']'+$("#"+id).find(".linkTitle").val()+'[/url]');
                        $("#"+id).remove();
                    }
                    else
                    {
                        $("#"+id).find(".picurl").parent().addClass("error_tip");
                        $("#"+id).find(".tip_txt").addClass("error_txt");
                        $("#"+id).find(".error_txt").html(errorMessage);
                    }
                });
            });


//            $(this).find('.edit_tool_link a').click(function(){
//                $(obj).find('.up_text').val($(obj).find('.up_text').val() + '[url=链接地址]链接标题[/url]');
//            });
        }

    };
    checkTitleUrl = function(title,url){
        if(($.trim(title)==''||$.trim(title)=='请输入标题内容')&&($.trim(url)==''||$.trim(url)=='请输入链接地址'))
            return '请输入标题内容与连接地址';
        else if(title.trueLength()>40||!$.ksPlugin.isUrl(url))
            return '标题内容超过20个字或链接地址错误';
        return '';
    };
})(jQuery);
globals.$(document).ready(function(){
    var timeOut1024;
    globals.$(".header_bg > .header > .h_nav > ul > li").hover(function(){
        clearTimeout(timeOut1024);
        globals.$(this).find(".h_nav_clo").addClass("h_nav_pull").parent().find(".nav_box").show();
    }, function(){
        var obj = this;
        timeOut1024 = setTimeout(function(){
            globals.$(obj).find(".h_nav_clo").removeClass("h_nav_pull").parent().find(".nav_box").hide();
        },500);
    });
    globals.UserStatus();
    globals.$.userCard(".show_userCard_link");
    if(!!globals.$.fancybox)
    {
        globals.$(".song_share_link").live("click", function(){
            var href = $(this).attr("link");
            $.fancybox.open({
                href: href,
                type: 'iframe',
                padding: 0,
                scrolling: "no",
                width: 490,
                height: 180,
                title: "分享"
            });
        });
    }
});